/*
题目链接 : https://leetcode.cn/problems/minimum-number-of-swaps-to-make-the-string-balanced/description/?envType=daily-question&envId=2025-03-17
*/

//题解代码 :

//贪心解法,合法括号对的任意前缀左括号>=右括号
class Solution {
public:
    int minSwaps(string s) {
        int ans = 0;
        int left = 0;
        for(auto& c : s){
            if(c=='[') ++left;
            else{
                if(left==0){
                    ++ans;
                    ++left;
                }else{
                    --left;
                }
            }
        }
        return ans;
    }
};
